package com.gozap.use;

public class StandardStore<E> implements Store<E> {

	private int capacity = 3;

	private int takeIndex = 0;
	private int putIndex = 0;
	E[] items;

	int size = 0;

	@SuppressWarnings("unchecked")
	public StandardStore() {
		items = (E[]) new Object[capacity];
	}

	public E take() {
		if (size < 0) {
			try {
				throw new Exception("wrong");
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
		E e = items[takeIndex];
		if (takeIndex == capacity - 1) {
			takeIndex = 0;
		} else {
			takeIndex++;
		}
		size--;
		return e;
	}

	public void put(E e) {
		if (size > capacity) {
			try {
				throw new Exception("wrong");
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
		items[putIndex] = e;
		if (putIndex == capacity - 1) {
			putIndex = 0;
		} else {
			putIndex++;
		}
		size++;

	}

	public boolean isFull() {
		return size == capacity;
	}

	public boolean isEmpty() {
		return 0 == size;
	}

	public int size() {
		return size;
	}

}
